6

import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

class Repo {
	private String items;
	private String[] task;
	ExecutorService exec = Executors.newFixedThreadPool(2);

	public Repo(String items) {
		this.items = items;
		task = items.split(" ");
		for (int i = 0; i < task.length; i++) {

			exec.execute(new Runnable() {
				@Override
				public void run() {
					try {
						Thread.sleep(1);
						System.out.println(Thread.currentThread().getName() + " finish " + task);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			});
		}

	}

	public int getSize() {
		return task.length;
	}

}

class Worker1 implements Runnable {

	@Override
	public void run() {
		try {
			wait();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		notify();
	}

	public Worker1(Repo repo) {

	}

}

class Worker2 implements Runnable {

	@Override
	public void run() {
		try {
			wait();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		notify();
	}

	public Worker2(Repo repo) {

	}
}


7

Executors.newSingleThreadExecutor();
        for (int i = 0; i < n; i++) {
            exec.execute(new Task(i));
        }


8 


	             CountDownLatch latch=new CountDownLatch(n);
	            
	            ExecutorService exec = Executors.newFixedThreadPool(poolSize);
	           
	            for (int i = 0; i < n; i++) {
					exec.execute(new MyTask(latch));
				}



9


Collections.synchronizedList(new ArrayList<Integer>());



10



        for (int i = 0; i < n; i++) {
            taskList.add(new CalculateTask());
        }
        for (int i = 0; i < n; i++) {
            results.add(exec.submit(new CalculateTask(i)));
        }
        for (Future<Integer> fs : results) {
            try {
                sum += fs.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }finally{
                exec.shutdown();
            }
        }
        System.out.println("sum="+sum);
    }
}

class CalculateTask implements Callable<Integer>{
	private int n;
	public CalculateTask(int n){
		this.n=n;
	}
	
	public CalculateTask() {
		super();
	}

	@Override
	public Integer call() throws Exception {
        int a = 1;
        int b = 1;
        for (int j = 1; j < n; j++) {
            int temp = a+b;
            a = b;
            b = temp;
        }
        return b;
	}
	
}
  package java2;

public class duoxiancheng {

}
